package com.css.fxfzaqbz.modules.maps.controller;

import com.css.fxfzaqbz.base.response.RestResponse;
import com.css.fxfzaqbz.modules.maps.vo.MapQueryVO;
import com.css.fxfzaqbz.modules.maps.vo.MapDelVO;
import com.css.fxfzaqbz.modules.maps.vo.MapUploadVO;
import com.css.fxfzaqbz.modules.maps.vo.MapViewVO;
import com.css.fxfzaqbz.modules.maps.service.MapManagerService;
import com.css.fxfzaqbz.util.ResponseCreator;
import org.springframework.web.bind.annotation.*;

import javax.annotation.Resource;
import javax.validation.constraints.NotBlank;
import java.util.List;

/**
 * @author Dbj
 * @date 2023年02月07日  9:56
 * @Desc 专业图件模板管理
 */
@RestController
@RequestMapping("/map")
public class MapManagerController {

    @Resource
    private MapManagerService mapManagerService;


    /**
     * @author Dongbj
     * @date 2023/2/7 14:19
     * @return null
     * @desc 获取图件类型
     */
    @GetMapping("/getMapType")
    public RestResponse getMapType(){
       return ResponseCreator.createSuccessResponse(mapManagerService.getMapType());
    }
    /**
     * 分页条件查询
     *
     * @param param
     * @return
     */
    @GetMapping("/page")
    public RestResponse page(MapQueryVO param) {
         return RestResponse.succeed(mapManagerService.page(param));
    }

    @PostMapping("/del")
    public RestResponse del(@RequestBody MapDelVO vo){
        if(vo.getIds().size()==0){
            return ResponseCreator.createFailResponse("删除失败，请选择要删除的数据");
        }
        mapManagerService.del(vo);
        return ResponseCreator.createSuccessResponse("删除成功");
    }

    @PostMapping("/uploadSave")
    public RestResponse uploadSave(@RequestBody MapUploadVO vo) throws Exception {
        return mapManagerService.uploadSave(vo);
    }

    @GetMapping("/view")
    public RestResponse view(@NotBlank(message="id不能为空")String id){
        MapViewVO vo = mapManagerService.view(id);
        return ResponseCreator.createSuccessResponse(vo);
    }

    @PostMapping("/update")
    public RestResponse update(@RequestBody MapViewVO vo){
        mapManagerService.update(vo);
        return ResponseCreator.createSuccessResponse("保存成功");
    }

    @GetMapping("/getTypeNameByType/{type}")
    public RestResponse getTypeNameByType(@PathVariable("type")String type){
        List<MapViewVO> mapViewVOList=mapManagerService.getTypeNameByType(type);
        return RestResponse.succeed(mapViewVOList);
    }


}
